﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SGS.Cards
{
    public class Card
    {
        #region Construct
        public static void ResetUniqueID()
        {
            dummy = 0;
        }

        static int dummy = 0;
        public Card(Suit suit, int point, CardType cardType)
            : this( ++dummy, suit, point, cardType )
        {
        }

        public Card(int uniqueID, Suit suit, int point, CardType cardtype)
        {
            UniqueID = uniqueID;
            Suit = suit;
            Point = point;
            CardType = cardtype;
        }
        #endregion

        #region Property
        public int UniqueID
        {
            get;
            protected set;
        }
        
        public Suit Suit
        {
            get;
            protected set;
        }

        public virtual CardColor CardColor
        {
            get
            {
                return CardLogicHelper.CheckCardColor( this );
            }
        }

        public int Point
        {
            get;
            protected set;
        }

        public virtual CardType CardType
        {
            get;
            protected set;
        }

        public virtual string Name
        {
            get
            {
                return NameMapping.Parse( CardType );
            }
        }
        #endregion

        #region Assistant
        public override string ToString()
        {
            return string.Format("ID={0}, {1}, {2}, {3}", this.UniqueID, this.Suit, this.Point, this.Name);
        }

        public List<Card> AsList()
        {
            return new List<Card>() { this };
        }
        #endregion

        #region Static Assistant Method
        public static void CopyCard(SGS.Cards.Card src, out SGS.Cards.Card dest)
        {
            dest = src;
        }

        public static void CopyCard(List<SGS.Cards.Card> src, out List<SGS.Cards.Card> dest)
        {
            dest = new List<SGS.Cards.Card>(src);
        }

        public static List<SGS.Cards.Card> CopyCard(List<SGS.Cards.Card> src)
        {
            List<SGS.Cards.Card> dest = null;
            CopyCard(src, out dest);
            return dest;
        }

        public static void MoveCard(ref SGS.Cards.Card src, out SGS.Cards.Card dest)
        {
            if (src == null)
            {
                dest = null;
                return;
            }
            else
            {
                dest = src;
                src = null;
            }
        }
        #endregion
    }
}
